```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java内部类详解 - 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .code-block {
            background-color: #f8f9fa;
            border-radius: 8px;
            border-left: 4px solid #667eea;
        }
        .card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
        }
        .highlight {
            color: #e53e3e;
            font-weight: 500;
        }
        .section-title {
            position: relative;
            padding-bottom: 10px;
        }
        .section-title:after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 50px;
            height: 3px;
            background: linear-gradient(to right, #667eea, #764ba2);
            border-radius: 3px;
        }
        .drop-cap::first-letter {
            float: left;
            font-size: 3.5em;
            line-height: 0.8;
            margin: 0.1em 0.1em 0 0;
            color: #667eea;
            font-weight: bold;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl flex flex-col items-center">
            <h1 class="text-4xl md:text-5xl font-bold mb-6 text-center font-serif">深入理解Java内部类</h1>
            <p class="text-xl md:text-2xl mb-8 text-center max-w-3xl font-serif">探索Java内部类的奥秘，提升代码组织能力</p>
            <div class="flex space-x-4">
                <a href="#what-is-inner-class" class="px-6 py-3 bg-white text-indigo-700 rounded-lg font-medium hover:bg-gray-100 transition duration-300">
                    <i class="fas fa-book-open mr-2"></i>开始学习
                </a>
                <a href="#homework" class="px-6 py-3 border-2 border-white text-white rounded-lg font-medium hover:bg-white hover:text-indigo-700 transition duration-300">
                    <i class="fas fa-laptop-code mr-2"></i>实践练习
                </a>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 py-12">
        <!-- What is Inner Class -->
        <section id="what-is-inner-class" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center mr-4">
                    <span class="text-indigo-600 text-xl font-bold">1</span>
                </div>
                <h2 class="text-3xl font-bold section-title font-serif">什么是内部类</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md p-6 card">
                <p class="text-lg mb-6 drop-cap">在一个类的内部定义的类称为内部类。内部类允许把一些<span class="highlight">逻辑相关</span>的类组织在一起，并且控制内部类的<span class="highlight">可视性</span>。</p>
                
                <div class="flex flex-col md:flex-row gap-8 mt-8">
                    <div class="flex-1">
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <i class="fas fa-check-circle text-green-500 mr-2"></i>内部类优势
                        </h3>
                        <ul class="space-y-3">
                            <li class="flex items-start">
                                <i class="fas fa-check text-indigo-500 mt-1 mr-2"></i>
                                <span>更好的代码组织和封装</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check text-indigo-500 mt-1 mr-2"></i>
                                <span>可以直接访问外部类的成员</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check text-indigo-500 mt-1 mr-2"></i>
                                <span>隐藏实现细节，提高安全性</span>
                            </li>
                        </ul>
                    </div>
                    
                    <div class="flex-1">
                        <div class="code-block p-4">
                            <pre class="text-sm overflow-x-auto">
<code>public class Outer {
    // 内部类定义
    class Inner {
        void show() {
            System.out.println("内部类方法");
        }
    }
}</code></pre>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Inner Class Types -->
        <section id="inner-class-types" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center mr-4">
                    <span class="text-indigo-600 text-xl font-bold">2</span>
                </div>
                <h2 class="text-3xl font-bold section-title font-serif">内部类的分类</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                <div class="p-6">
                    <div class="flex flex-col md:flex-row gap-8">
                        <div class="flex-1">
                            <h3 class="text-xl font-semibold mb-4 flex items-center">
                                <i class="fas fa-project-diagram text-purple-500 mr-2"></i>内部类类型图解
                            </h3>
                            <img src="https://cdn.nlark.com/yuque/0/2023/png/21449790/1692781022013-e510b553-6365-4980-a1f3-3cd09d63eee3.png" alt="内部类分类" class="w-full rounded-lg shadow-sm mb-4">
                            <img src="https://cdn.nlark.com/yuque/0/2023/png/21449790/1692781022272-db8b5956-0a64-472f-8ed3-6b71eb47ebaa.png" alt="内部类访问修饰符" class="w-full rounded-lg shadow-sm">
                        </div>
                        
                        <div class="flex-1">
                            <div class="mb-6">
                                <h4 class="text-lg font-semibold mb-3 text-indigo-700">成员内部类的访问修饰符</h4>
                                <p>成员内部类的访问修饰符跟成员变量是一样的，可以是默认(default)，private，protected，public。</p>
                            </div>
                            
                            <div class="code-block p-4">
                                <pre class="text-sm overflow-x-auto">
<code>public class Outer {
    // 默认内部类
    class DefaultInner {}
    
    // private内部类
    private class PrivateInner {}
    
    // protected内部类
    protected class ProtectedInner {}
    
    // public内部类
    public class PublicInner {}
}</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Member Inner Class -->
        <section id="member-inner-class" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center mr-4">
                    <span class="text-indigo-600 text-xl font-bold">3</span>
                </div>
                <h2 class="text-3xl font-bold section-title font-serif">成员内部类-实例内部类（非静态内部类）</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md p-6 card">
                <p class="text-lg mb-6">实现效果：首先提供一个计算的功能，该功能的核心实现交给内部类来实现。</p>
                
                <img src="https://cdn.nlark.com/yuque/0/2023/png/21449790/1692781022545-c608d280-2c43-4d05-8310-b50c56185964.png" alt="实例内部类示例" class="w-full rounded-lg shadow-sm mb-6">
                
                <div class="bg-yellow-50 border-l-4 border-yellow-400 p-4 mb-6">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-exclamation-circle text-yellow-500"></i>
                        </div>
                        <div class="ml-3">
                            <p class="text-sm text-yellow-700">
                                注意：此处案例只是对内部类的使用有个基本的认识，后面继续深入理解内部类。
                            </p>
                        </div>
                    </div>
                </div>
                
                <div class="grid md:grid-cols-2 gap-8">
                    <div>
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <i class="fas fa-code-branch text-blue-500 mr-2"></i>3.1 内部类可以访问外部类的所有属性和方法
                        </h3>
                        <img src="https://cdn.nlark.com/yuque/0/2023/png/21449790/1692781022910-908ba70f-12c7-4d83-abe8-8454d77cca80.png" alt="内部类访问外部类成员" class="w-full rounded-lg shadow-sm mb-4">
                        <img src="https://cdn.nlark.com/yuque/0/2023/png/21449790/1692781023171-5c1d0619-59fa-4659-ad9b-8ab1e6a0d380.png" alt="内部类访问外部类成员示例" class="w-full rounded-lg shadow-sm">
                    </div>
                    
                    <div>
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <i class="fas fa-exclamation-triangle text-orange-500 mr-2"></i>3.2 内部类和外部类存在同名变量（了解即可）
                        </h3>
                        <p class="mb-4">如果内部类和外部类拥有同名的变量，那么要怎么区分？</p>
                        <img src="https://cdn.nlark.com/yuque/0/2023/png/21449790/1692781023438-33efd2f7-a3f8-45e9-b441-b1186d8f53f4.png" alt="同名变量处理" class="w-full rounded-lg shadow-sm">
                    </div>
                </div>
            </div>
        </section>

        <!-- Static Inner Class -->
        <section id="static-inner-class" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center mr-4">
                    <span class="text-indigo-600 text-xl font-bold">4</span>
                </div>
                <h2 class="text-3xl font-bold section-title font-serif">成员内部类-静态内部类</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md p-6 card">
                <p class="text-lg mb-6">创建静态内部类的实例，无需创建外部类的实例，详见案例。</p>
                
                <div class="bg-blue-50 border-l-4 border-blue-400 p-4 mb-6">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-info-circle text-blue-500"></i>
                        </div>
                        <div class="ml-3">
                            <p class="text-sm text-blue-700">
                                要注意下面创建静态内部类实例的方式
                            </p>
                        </div>
                    </div>
                </div>
                
                <img src="https://cdn.nlark.com/yuque/0/2023/png/21449790/1692781023752-a75dd6c0-b2a1-4d58-bab3-a94ff510002a.png" alt="静态内部类示例" class="w-full rounded-lg shadow-sm mb-6">
                
                <div class="bg-red-50 border-l-4 border-red-400 p-4">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-question-circle text-red-500"></i>
                        </div>
                        <div class="ml-3">
                            <h4 class="text-lg font-semibold text-red-800 mb-2">问题：</h4>
                            <p class="text-sm text-red-700">
                                静态内部类是否可以使用外部类的非静态成员变量？<br>
                                因为静态内部类实例的存在，不需要建立在外部类实例存在的前提下，所以静态内部类不能直接访问外部类的非静态变量。
                            </p>
                        </div>
                    </div>
                </div>
                
                <img src="https://cdn.nlark.com/yuque/0/2023/png/21449790/1692781024029-2dc50f82-d9b9-4847-9f13-e24bd54d2d11.png" alt="静态内部类限制" class="w-full rounded-lg shadow-sm mt-6">
            </div>
        </section>

        <!-- Local Inner Class -->
        <section id="local-inner-class" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center mr-4">
                    <span class="text-indigo-600 text-xl font-bold">5</span>
                </div>
                <h2 class="text-3xl font-bold section-title font-serif">局部内部类</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md p-6 card">
                <p class="text-lg mb-6">局部内部类是在一个方法内定义的内部类，其可见范围是当前方法，和局部变量一样，局部内部类不能采用访问控制修饰符(private, protected, public, static)来修饰。</p>
                
                <img src="https://cdn.nlark.com/yuque/0/2023/png/21449790/1692781024311-0fd3c542-afc8-4870-b1a7-5e681f509a37.png" alt="局部内部类示例" class="w-full rounded-lg shadow-sm">
                
                <div class="mt-6 grid md:grid-cols-2 gap-6">
                    <div class="code-block p-4">
                        <pre class="text-sm overflow-x-auto">
<code>public class Outer {
    public void method() {
        // 局部内部类
        class LocalInner {
            void show() {
                System.out.println("局部内部类");
            }
        }
        
        LocalInner inner = new LocalInner();
        inner.show();
    }
}</code></pre>
                    </div>
                    
                    <div class="bg-green-50 border-l-4 border-green-400 p-4">
                        <div class="flex">
                            <div class="flex-shrink-0">
                                <i class="fas fa-lightbulb text-green-500"></i>
                            </div>
                            <div class="ml-3">
                                <h4 class="text-lg font-semibold text-green-800 mb-2">特点：</h4>
                                <ul class="text-sm text-green-700 space-y-1">
                                    <li>• 定义在方法或作用域内</li>
                                    <li>• 不能使用访问修饰符</li>
                                    <li>• 只能访问final或有效final的局部变量</li>
                                    <li>• 作用域仅限于声明它的块中</li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Anonymous Inner Class -->
        <section id="anonymous-inner-class" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center mr-4">
                    <span class="text-indigo-600 text-xl font-bold">6</span>
                </div>
                <h2 class="text-3xl font-bold section-title font-serif">匿名内部类（常用）</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md p-6 card">
                <p class="text-lg mb-6">没有名字的内部类，如果说该类只需要创建一次对象且该对象只使用一次，则不需要去创建该类，建议采用匿名内部类的方式，减少类的个数。</p>
                
                <div class="grid md:grid-cols-2 gap-6">
                    <div>
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <i class="fas fa-code text-purple-500 mr-2"></i>匿名内部类语法
                        </h3>
                        <div class="code-block p-4">
                            <pre class="text-sm overflow-x-auto">
<code>new 父类构造器(参数列表) {
    // 匿名内部类的类体部分
    方法重写
}

// 或实现接口
new 接口() {
    // 实现接口的方法
}</code></pre>
                        </div>
                    </div>
                    
                    <div>
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <i class="fas fa-example text-blue-500 mr-2"></i>示例代码
                        </h3>
                        <div class="code-block p-4">
                            <pre class="text-sm overflow-x-auto">
<code>// 使用匿名内部类实现接口
Runnable r = new Runnable() {
    @Override
    public void run() {
        System.out.println("匿名内部类");
    }
};

// 使用匿名内部类继承类
Thread t = new Thread() {
    @Override
    public void run() {
        System.out.println("线程运行");
    }
};</code></pre>
                        </div>
                    </div>
                </div>
                
                <div class="mt-6 bg-indigo-50 border-l-4 border-indigo-400 p-4">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-star text-indigo-500"></i>
                        </div>
                        <div class="ml-3">
                            <h4 class="text-lg font-semibold text-indigo-800 mb-2">应用场景：</h4>
                            <ul class="text-sm text-indigo-700 space-y-1">
                                <li>• 事件监听器</li>
                                <li>• 线程实现</li>
                                <li>• 一次性使用的类</li>
                                <li>• 简化代码结构</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Inner Class Files -->
        <section id="inner-class-files" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center mr-4">
                    <span class="text-indigo-600 text-xl font-bold">7</span>
                </div>
                <h2 class="text-3xl font-bold section-title font-serif">内部类的类文件</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md p-6 card">
                <p class="text-lg mb-6">对于每个内部类来说，Java编译器都会为其生成独立的类文件。</p>
                <p class="mb-6">做实验观察内部类的类文件名规则。</p>
                
                <div class="code-block p-4 mb-6">
                    <pre class="text-sm overflow-x-auto">
<code>// 编译后生成的类文件
Outer.class          // 外部类
Outer$Inner.class    // 成员内部类
Outer$1LocalInner.class  // 局部内部类
Outer$1.class        // 匿名内部类</code></pre>
                </div>
                
                <div class="bg-gray-100 rounded-lg p-4">
                    <h4 class="text-lg font-semibold mb-3 flex items-center">
                        <i class="fas fa-file-alt text-gray-600 mr-2"></i>命名规则总结：
                    </h4>
                    <ul class="text-gray-700 space-y-2">
                        <li class="flex items-start">
                            <span class="text-gray-500 mr-2">•</span>
                            <span>成员内部类：<code>外部类名$内部类名.class</code></span>
                        </li>
                        <li class="flex items-start">
                            <span class="text-gray-500 mr-2">•</span>
                            <span>局部内部类：<code>外部类名$数字+内部类名.class</code>（如果有名字）</span>
                        </li>
                        <li class="flex items-start">
                            <span class="text-gray-500 mr-2">•</span>
                            <span>匿名内部类：<code>外部类名$数字.class</code></span>
                        </li>
                    </ul>
                </div>
            </div>
        </section>

        <!-- Homework -->
        <section id="homework" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center mr-4">
                    <span class="text-indigo-600 text-xl font-bold">8</span>
                </div>
                <h2 class="text-3xl font-bold section-title font-serif">作业</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md p-6 card">
                <div class="mb-6">
                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-laptop-code text-green-500 mr-2"></i>基础作业
                    </h3>
                    <p class="text-lg mb-4">有一段可以执行的程序，我们想测试它的执行时间到底花了多久？</p>
                </div>
                
                <div>
                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-trophy text-orange-500 mr-2"></i>挑战题
                    </h3>
                    <p class="text-lg mb-6">具体测试的内容是不确定的帮我写一个工具类，提供测试代码执行时间的功能，这段代码肯定是可以执行。</p>
                    
                    <div class="code-block p-4">
                        <pre class="text-sm overflow-x-auto">
<code>public class TimeUtils {
    /**
     * 计算代码执行时间
     * @param code 要执行的代码块
     * @return 执行时间(毫秒)
     */
    public static long calculateTime(Runnable code) {
        long start = System.currentTimeMillis();
        code.run();
        long end = System.currentTimeMillis();
        return end - start;
    }
    
    // 使用示例
    public static void main(String[] args) {
        long time = calculateTime(() -> {
            // 你的测试代码
            int sum = 0;
            for (int i = 0; i < 1000000; i++) {
                sum += i;
            }
        });
        
        System.out.println("执行时间: " + time + "ms");
    }
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Concept Map -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md p-6 card">
                <h2 class="text-2xl font-bold mb-6 text-center font-serif">Java内部类概念关系图</h2>
                <div class="mermaid">
                    graph TD
                        A[Java内部类] --> B[成员内部类]
                        A --> C[局部内部类]
                        A --> D[匿名内部类]
                        B --> E[实例内部类]
                        B --> F[静态内部类]
                        C --> G[方法内定义]
                        C --> H[作用域内定义]
                        D --> I[实现接口]
                        D --> J[继承类]
                        E --> K[可访问外部类成员]
                        F --> L[不能访问外部类非静态成员]
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-white py-8">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-bold">技术小馆</h3>
                    <p class="text-gray-400 mt-1">探索编程世界的美妙</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-gray-300 hover:text-white transition duration-300">
                        <i class="fas fa-globe mr-2"></i>http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
            <div class="mt-8 pt-6 border-t border-gray-800 text-center text-gray-400 text-sm">
                &copy; 2023 技术小馆. All rights reserved.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```